package com.zhuhao.basic.proxy.cglib;

import com.zhuhao.basic.proxy.cglib.goal.HelloService;
import net.sf.cglib.proxy.Enhancer;

/**
 * 生成代理对象
 * @Author haozhu7
 * @Date 2025/5/23 10:57
 **/
public class CglibProxyExample {
    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(HelloService.class);
        enhancer.setCallback(new MyMethodInterceptor());
        HelloService proxy = (HelloService) enhancer.create();

        //方法的返回值被增强（追加了“: Proxy”字符串）
        String name = proxy.sayHello("小丽", 23);
        System.out.println(name);
    }
}